class Solution:
    @staticmethod
    def generate(numRows):
        """
        生成杨辉三角的前 numRows 行
        时间复杂度: O(n^2)，空间复杂度: O(n^2)
        """
        triangle = []
        for i in range(numRows):
            row = [1] * (i + 1)  # 每行初始化为1
            for j in range(1, i):  # 跳过首尾的1
                row[j] = triangle[i-1][j-1] + triangle[i-1][j]  # 递推公式
            triangle.append(row)
        return triangle